import { Injectable } from '@angular/core';
/**
 * set global data like $rootScope
 * 
 */
@Injectable()
export class GlobalData {
    private _token: string;
    private _scope: any = {};
    private _product: any;
    // current cart
    private _curCart: any;
    private _curMember: any;
    // home curTab: 'serving' or 'order'
    private _curTab: string;
    private _tableList: any;
    private _tableAmount: number;
    private _warehouse: any;
    private _curUser: any;
    // sandbox & production mode, translate key
    private _curEnvir: any;
    // online & offline mode, translate key
    private _curMode: any;
    private _curLang: any;
    private _curPrintLang: any;
    private _isPrintByDepartment: boolean;
    private _curEpsonPrinters: any;
    private _departments: any;
    private _curPrinter: any;
    private _shopIconFile: string;

    public get shopIconFile(): string {
        if (!this._shopIconFile) {
            return '';
        }
        return this._shopIconFile;
    }

    public set shopIconFile(value: string) {
        this._shopIconFile = value;
    }

    public get curLang(): any {
        if (!this._curEnvir) {
            return 'EN_US';
        }
        return this._curLang;
    }

    public set curLang(value: any) {
        this._curLang = value;
    }

    public get isPrintByDepartment(): boolean {
        if (!this._isPrintByDepartment) {
            return false;
        }
        return this._isPrintByDepartment;
    }

    public set isPrintByDepartment(value: boolean) {
        this._isPrintByDepartment = value;
    }

    public get curPrintLang(): any {
        if (!this._curPrintLang) {
            return 'EN_US';
        }
        return this._curPrintLang;
    }

    public set curPrintLang(value: any) {
        this._curPrintLang = value;
    }

    public get curEnvir(): any {
        if (!this._curEnvir) {
            return 'SANDBOX_MODE';
        }
        return this._curEnvir;
    }

    public set curEnvir(value: any) {
        this._curEnvir = value;
    }

    public get curMode(): any {
        if (!this._curEnvir) {
            return 'ONLINE_MODE';
        }
        return this._curMode;
    }

    public set curMode(value: any) {
        this._curMode = value;
    }

    public get curUser(): any {
        if (!this._curUser) {
            return {
                name: '',
                login: '',
                warehouse_EN_US: '',
                warehouse_ZH_HK: '',
                warehouse_ZH_CN: ''
            };
        }
        return this._curUser;
    }

    public set curUser(value: any) {
        this._curUser = value;
    }

    public get curItem(): any {
        return this._curItem;
    }

    public set curItem(value: any) {
        this._curItem = value;
    }
    private _curItem: any;

    public get curTab(): string {
        if (!this._curTab)
            return 'serving';
        return this._curTab;
    }

    public set curTab(value: string) {
        this._curTab = value;
    }

    public get warehouse(): any {
        if (!this._warehouse) {
            return {
                warehouse_id: 0,
                warehouse_tel: 8888888,
                warehouse_EN_US: '',
                warehouse_ZH_HK: '',
                warehouse_ZH_CN: ''
            };
        }
        return this._warehouse;
    }

    public set warehouse(value: any) {
        this._warehouse = value;
    }

    public get product(): any {
        return this._product;
    }

    public set product(value: any) {
        this._product = value;
    }

    public get token(): string {
        return this._token;
    }

    public set token(value: string) {
        this._token = value;
    }

    public get curCart(): any {
        if (!this._curCart)
            return {
                "id": null,
                "invoice_no": null,
                "table_num": 0,
                "item_total": 0,
                "discount_total": 0,
                "delivery_total": 0,
                "service_total": 0,
                "temp_grand_total": 0,
                "payed_amount": 0,
                "products": [],
                "invoice_charges": []
            };
        return this._curCart;
    }

    public set curCart(value: any) {
        this._curCart = value;
    }

    public get curMember(): any {
        if (!this._curMember)
            return {
                "user_id": 0,
                "member_id": 0,
                "vip_level": '',
                "customer_name": ''
            };
        return this._curMember;
    }

    public set curMember(value: any) {
        this._curMember = value;
    }

    public get tableList(): any {
        if (!this._tableList)
            return [];
        return this._tableList;
    }

    public set tableList(value: any) {
        this._tableList = value;
    }


    public get tableAmount(): number {
        if (!this._tableAmount)
            return 50;

        return this._tableAmount;
    }

    public set tableAmount(value: number) {
        this._tableAmount = value;
    }

    public setScope(key, val) {
        this._scope[key] = val;
    }

    public getScope(key) {
        try {
            return this._scope[key];
        }
        catch (err) {
            return null;
        }
    }

    public clearScope(key) {
        delete this._scope[key];
    }

    public get curEpsonPrinters(): any {
        return this._curEpsonPrinters;
    }

    public set curEpsonPrinters(value: any) {
        this._curEpsonPrinters = value;
    }

    public get departments(): any {
        if (!this._departments) {
            return [];
        }
        return this._departments;
    }

    public set departments(value: any) {
        this._departments = value;
    }

    public get curPrinter(): any {
        return this._curPrinter;
    }

    public set curPrinter(value: any) {
        this._curPrinter = value;
    }

}